//
//  HACBrush.h
//  HStockCharts
//
//  Created by Hotacool on 2018/9/13.
//

#import <Foundation/Foundation.h>
#import "HACChartDataProvider.h"

#define DISABLE_ANIMATION_BEIGIN [CATransaction begin]; \
[CATransaction setDisableActions:YES];

#define DISABLE_ANIMATION_END [CATransaction commit];

@class UIBezierPath;

@interface HACBrush : NSObject
@property (nonatomic, weak) id<HACChartDataProvider> provider;

- (instancetype)initWithDataProvider:(id<HACChartDataProvider>)provider ;

- (void)drawInLayer:(CALayer*)layer inRect:(CGRect)rect;

- (void)clean;

- (void)removeBrush;

#pragma mark -- utility methods
- (NSArray<NSArray*>*)_generateSubPointsFromArray:(NSArray*)points;
- (UIBezierPath*)_generatePathFromPoints:(NSArray*)pointsArray
                                isSmooth:(BOOL)isSmooth ;
- (UIBezierPath*)_generatePathFromPoints:(NSArray*)pointsArray
                                isSmooth:(BOOL)isSmooth
                               fillColor:(UIColor*)fillColor
                                  InRect:(CGRect)rect;
- (UIBezierPath*)_generateCandlePathInRect:(CGRect)rect
                                 highPoint:(CGPoint)hp
                                  lowPoint:(CGPoint)lp
                                    isFill:(BOOL)isFill;
@end

@protocol HACAsynchronousAble;
@interface HACPainterPool : NSObject
+ (instancetype)pool;
// 返回unused或者空
- (id<HACAsynchronousAble>)pop;
- (void)push:(id<HACAsynchronousAble>)painter isUsed:(BOOL)isUsed;
- (NSArray*)allPainters;
- (HACPainterPool*)freePool;
@end
